﻿CREATE TRIGGER [tr_Menu_Delete_TabIndex]
ON [dbo].[t_Menu]
FOR DELETE
AS

DELETE t_WorkFlow FROM t_WorkFlow
INNER JOIN deleted d ON d.MenuID IN (t_WorkFlow.MenuID,t_WorkFlow.NextMenuID)

UPDATE t_Menu
SET TabIndex = t_Menu.TabIndex-1 FROM t_Menu
INNER JOIN deleted d ON t_Menu.ParentMenuID = d.ParentMenuID AND t_Menu.TabIndex >= d.TabIndex
